const User = require('../models/user')

async function checkUserAuthorization(ctx, next) {
    const user = await User.findById(ctx.state.user._id).select('auth')
    const auth = user.auth
    if (auth === '0') {
        ctx.throw(403, '没有授权')
    } else if (auth === '1'){
        await next()
    } else {
        ctx.throw(401, '请重新登录')
    }
}

module.exports = checkUserAuthorization